﻿/// <reference path="../Turbo/Turbo.js" />

TA.Turbo.Common._DoPostBack_Validate = function _DoPostBack_Validate(scenario)
{
	var causesValidation = true, validationGroups = new Array();
	if (scenario != null)
	{
		validationGroups = scenario.ValidationGroupList;
		causesValidation = scenario.CausesValidation;
	}

	var validationResult = true;
	if (causesValidation)
	{
		// we gonna move val. groups to an Object and use hash map to check against - faster than 
		// parsing array multiple times
		var validationGroupsHash = null;
		if (validationGroups.length > 0)
		{
			validationGroupsHash = new Object();
			for (var iValGroup = 0; iValGroup < validationGroups.length; ++iValGroup)
			{
				validationGroupsHash[validationGroups[iValGroup]] = true;
			}
		}

		for (var iValidator = 0; iValidator < TA.Turbo.Common.Validators.length; ++iValidator)
		{
			var validator = TA.Turbo.Common.Validators[iValidator];

			if (validationGroupsHash != null) // if not null, we have some val. groups
			{
				if (validationGroupsHash[validator.get_Group()] !== true)
					continue;
			}
			var isValid = validator.get_IsValid();
			validationResult = validationResult && isValid;
		}
	}
	return validationResult;
}